Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
JavaScript arrays and understanding arr[arr.length]

What is meant by arr[arr.length]. I mean what it really means or what it really does, I cannot understand the logic of how it works. Can anybody explain?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

This statement gets the index of the last index of the array plus one. It is used to append items to an array. Equivalent to array.push().

var fruits = ["apple", "orange", "banana", "pear"];
// appends grapes to the array
fruits[fruits.length] = "grapes";
console.log(fruits);

For further reading, check out W3School's page on array methods.

about 4 years ago · Juan Pablo Isaza Denunciar

0

arr.length is the length of the array.

arr[arr.length] is accessing by index the array length (out of bounds as length starts at 1, not index 0).

example:

const test = [1,2,3]
test[test.length]
undefined
test[test.length-1]
3
about 4 years ago · Juan Pablo Isaza Denunciar

0

arr.length means the length of the array that spans from index 0 to arr.length - 1.

For instance if you got arr = ["a", "b", "c"], arr.length is 3.

arr[0] is "a", arr[1] is "b" and arr[2] is "c".

arr[3] does not exist, yet. but if you do arr[arr.length] = "d", you obtain ["a", "b", "c", "d"].

This is an odd construction and usually, one should simply write arr.push("d").

const arr = ["a", "b", "c"];
console.log(arr.length, arr[0], arr[1], arr[2], arr[3]);
arr[arr.length] = "d";
console.log(arr);
arr.push("e");
console.log(arr);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda